<template>
	<div class="front bj bg-white" v-loading="loading" element-loading-text="数据加载中..." element-loading-spinner="el-icon-loading" element-loading-background="#fff">
		<el-scrollbar style="height: 100%;">
			<el-table :data="tableData" border @row-dblclick="rowDBClick">
				<el-table-column property="name" label="姓名" align="center"></el-table-column>
				<el-table-column property="sex" label="性别" align="center">
					<template slot-scope="scope">
						<span v-if="scope.row.sex === 0">女</span>
						<span v-if="scope.row.sex === 1">男</span>
					</template>
				</el-table-column>
				<el-table-column  property="deptName" label="部门" align="center"></el-table-column>
				<el-table-column property="positionAux" label="职务" align="center"></el-table-column>
			</el-table>
		</el-scrollbar>
	</div>
</template>
<script>
export default {
	data() {
		return {
			loading: true,
			tableData: [],
		}
	},
	computed: {
		systemId() {
			return this.$store.state.systemId;
		}
	},
	methods: {
		getData(row) {
			let deptId = this.$store.state.verifyProcessStore.deptId;			//当前操作的部门id
			deptId = deptId > 0 ? deptId : 0;
			this.loading = true;
			this.$http.get('employee/findEmployeeByDepartment?systemId=' + this.systemId + '&id=' + deptId).then(res => {
                if(res.data.code == 20001) {
                    setTimeout(() => {
                    	this.loading = false;
                    	if(res.data.data) {
	                        this.tableData = res.data.data;
	                    }
                    }, 250);
                } else {
                	setTimeout(() => {
                    	this.loading = false;
                    	this.tableData = [];
                    }, 250);
                }
            }).catch(() => {
            	setTimeout(() => {
                	this.loading = false;
                	this.tableData = [];
                }, 250);
            });
		},
		rowDBClick(row) {			//双击表格行触发
			let store = this.$store.state.verifyProcessStore;
			let data = {
				id: row['id'],
				name: row['name'],
				level: 3,
				billId: store.billId,
				vercharId: store.vercharId,
				pid: store.deptId,
				children: [],
				subList: [
					{
						id: store.dfId,
						name: store.minMoney + ' ~ ' + store.maxMoney,
						level: 4,
						money1: store.minMoney,
                        money2: store.maxMoney,
                        billId: store.billId,
                        vercharId: store.vercharId,
                        deptId: store.deptId,
                        pid: row['id'],
                        children: [],
                        subList: []
					}
				]
			}
			this.$store.commit('verifyProcessStore/appendNode', data);
			this.close();
		},
		close() {		//关闭
            let index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }
	},
	created() {
		this.getData();
	}
}
</script>